Solve the msgctxt problem a bit more elegantly, and add some hints about
authorMatthias Clasen <matthiasc@src.gnome.org>
Sun, 18 Jan 2009 19:00:18 +0000 (19:00 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sun, 18 Jan 2009 19:00:18 +0000 (19:00 +0000)
        * gtk/gtkstock.c: Solve the msgctxt problem a bit more
        elegantly, and add some hints about this to the docs of
        gtk_stock_set_translate_func. Proposed by Christian Persch

svn path=/trunk/; revision=22137

ChangeLog
gtk/gtkstock.c

index b503234cce769bebde2005dba68d8b6edce8fa77..7fb468efe735ebc1b4da8c419d60e5bfb9d65ee2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-01-18  Matthias Clasen  <mclasen@redhat.com>
+
+       Bug 563280 – stock items & translation context
+
+       * gtk/gtkstock.c: Solve the msgctxt problem a bit more
+       elegantly, and add some hints about this to the docs of
+       gtk_stock_set_translate_func. Proposed by Christian Persch
+
 2009-01-18  Matthias Clasen  <mclasen@redhat.com>
 
        Bug 568196 – Please change context of Forward stock label
index 6b2951037ba45437da564995c66a262629f5eb37..53562eb98a554fbc9699fe2934ba4a4dbfc4f9ba 100644 (file)
@@ -425,12 +425,40 @@ static const GtkStockItem builtin_items [] =
  *
  * Sets a function to be used for translating the @label of 
  * a stock item.
- *
+ * 
  * If no function is registered for a translation domain,
  * g_dgettext() is used.
+ * 
+ * The function is used for all stock items whose
+ * @translation_domain matches @domain. Note that it is possible
+ * to use strings different from the actual gettext translation domain
+ * of your application for this, as long as your #GtkTranslateFunc uses
+ * the correct domain when calling dgettext(). This can be useful, e.g.
+ * when dealing with message contexts:
  *
- * Since: 2.8
+ * |[
+ * GtkStockItem items[] = { 
+ *  { MY_ITEM1, NC_("odd items", "Item 1"), 0, 0, "odd-item-domain" },
+ *  { MY_ITEM2, NC_("even items", "Item 2"), 0, 0, "even-item-domain" },
+ * };
+ *
+ * gchar *
+ * my_translate_func (const gchar *msgid,
+ *                    gpointer     data)
+ * {
+ *   gchar *msgctxt = data;
  * 
+ *   return (gchar*)g_dpgettext2 (GETTEXT_PACKAGE, msgctxt, msgid);
+ * }
+ *
+ * /&ast; ... &ast/
+ *
+ * gtk_stock_add (items, G_N_ELEMENTS (items));
+ * gtk_stock_set_translate_func ("odd-item-domain", my_translate_func, "odd-item-domain"); 
+ * gtk_stock_set_translate_func ("even-item-domain", my_translate_func, "even-item-domain"); 
+ * ]|
+ * 
+ * Since: 2.8
  */
 void
 gtk_stock_set_translate_func (const gchar      *domain,
@@ -465,24 +493,11 @@ static gchar *
 sgettext_swapped (const gchar *msgid, 
                  gpointer     data)
 {
-  return (gchar *)g_dpgettext2 ((const char *)data, "Stock label", msgid);
-}
+  gchar *msgctxt = data;
 
-static gchar *
-sgettext_swapped_navigation (const gchar *msgid, 
-                            gpointer     data)
-{
-  return (gchar *)g_dpgettext2 ((const char *)data, "Stock label, navigation", msgid);
+  return (gchar *)g_dpgettext2 (GETTEXT_PACKAGE, msgctxt, msgid);
 }
 
-static gchar *
-sgettext_swapped_media (const gchar *msgid, 
-                       gpointer     data)
-{
-  return (gchar *)g_dpgettext2 ((const char *)data, "Stock label, media", msgid);
-}
-
-
 static void
 init_stock_hash (void)
 {
@@ -500,15 +515,15 @@ init_stock_hash (void)
 
       gtk_stock_set_translate_func (GETTEXT_PACKAGE, 
                                    sgettext_swapped,
-                                   GETTEXT_PACKAGE,
+                                   "Stock label",
                                    NULL);
       gtk_stock_set_translate_func (GETTEXT_PACKAGE "-navigation", 
-                                   sgettext_swapped_navigation,
-                                   GETTEXT_PACKAGE,
+                                   sgettext_swapped,
+                                   "Stock label, navigation",
                                    NULL);
       gtk_stock_set_translate_func (GETTEXT_PACKAGE "-media", 
-                                   sgettext_swapped_media,
-                                   GETTEXT_PACKAGE,
+                                   sgettext_swapped,
+                                   "Stock label, media",
                                    NULL);
     }
 }